/////////////////////////////////////////////////////////////////////////////
//  Copyright(c)2008, Qizhi Zhang. http://www.moorwind.com. 
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
/////////////////////////////////////////////////////////////////////////////
package net.oauth
{
	/**
	 * Unless otherwise specified by the Service Provider, the timestamp is expressed 
	 * in the number of seconds since January 1, 1970 00:00:00 GMT. 
	 * The timestamp value MUST be a positive integer and MUST be equal or greater than the timestamp used in previous requests. 
	 * The Consumer SHALL then generate a Nonce value that is unique for all requests with that timestamp. 
	 * A nonce is a random string, uniquely generated for each request. 
	 * The nonce allows the Service Provider to verify that a request has never been made before 
	 * and helps prevent replay attacks when requests are made over a non-secure channel (such as HTTP). 
	 * 
	 * <br/><br/>生成OAuth验证Nonce与TimeStamp
	 * 
	 * @author Qizhi Zhang
	 */
	public class Nonce
	{
		/**
		 * A nonce is a random string, uniquely generated for each request. 
		 * <br/><br/>获取OAuth Nonce
		 * 
		 */
		internal static function get OAuthNonce():String
		{
			var _date	:Date = new Date();
			var _UTCDate:Date = new Date( _date.getUTCFullYear() + 1970, 
										_date.getUTCMonth(), 
										_date.getUTCDate(), 
										_date.getUTCHours(), 
										_date.getUTCMinutes(), 
										_date.getUTCSeconds(), 
										_date.getUTCMilliseconds() ); 
			return 	( _UTCDate.getTime() * 10000 ).toString();	
		}
		
		/**
		 * the timestamp is expressed in the number of seconds since January 1, 1970 00:00:00 GMT
		 * <br/><br/>获取OAuth timestamp
		 * 
		 */
		internal static function get OAuthTimeStamp():String
		{
			var _date:Date = new Date();
			return int( _date.getTime()/1000 ).toString();
		}
	}
}